import axios from './axios'
import qs from 'qs'


export function getEmployeeList() {
    return axios.get('/employee/manage/all_employee.do').then(res => Promise.resolve(res.data))
}

export function getCustomerList() {
    return axios.get('/service/custom_list.do').then(res => Promise.resolve(res.data))
}

export function getRequestNo() {
    return axios.get('/manage/search/get_request_no.do').then(res => Promise.resolve(res.data))
}

export function getQuestList(pageNum = 1, pageSize = 1000) {
    return axios.post('/manage/order/show_service.do', qs.stringify({
        pageNum,
        pageSize
    })).then(res => Promise.resolve(res.data))
}

export function searchQuest(customerName, unitModel) {
    return axios.post('/manage/order/select_service.do', qs.stringify({
        customerName,
        unitModel
    })).then(res => Promise.resolve(res.data))
}

export function getPlateNo() {
    return axios.post('/service/service_information_list.do').then(res => Promise.resolve(res.data))
}

export function getDeviceInfo({plateNum}) {
    return axios.post('/service/service_by_plateNum.do', qs.stringify({plateNum})).then(res => Promise.resolve(res.data))
}

export function subQuest({
                             requestNo, requestDate, initiator, customerId, customerName, addressId, address, distance, unitModel, sn,
                             deliveryTime, hmKm, typeCode, serviceType, appointmentTime, note, status, projectName, plateNum,
                             charges, problems, operator
                         }) {
    const data = qs.stringify({
        requestNo, requestDate, initiator, customerId, customerName, addressId, address, distance, unitModel, sn,
        deliveryTime, hmKm, typeCode, serviceType, appointmentTime, note, status, projectName, plateNum,
        charges, problems, operator
    });
    return axios.post('/manage/order/request_service.do', data).then(res => Promise.resolve(res.data))

}

export function modQuest({
                             requestNo, requestDate, initiator, customerId, customerName, addressId, address, distance, unitModel, sn,
                             deliveryTime, hmKm, typeCode, serviceType, appointmentTime, note, status, projectName, plateNum,
                             charges, problems, operator, id
                         }) {
    const data = qs.stringify({
        requestNo, requestDate, initiator, customerId, customerName, addressId, address, distance, unitModel, sn,
        deliveryTime, hmKm, typeCode, serviceType, appointmentTime, note, status, projectName, plateNum, operator, id,
        charges, problems
    });
    return axios.post('/manage/order/update_service.do', data).then(res => Promise.resolve(res.data))

}

export function showQuestDetail(id) {
    return axios.post('/manage/order/show_service_detail.do', qs.stringify({id})).then(res => Promise.resolve(res.data))
}

export function deleteQuest(id) {
    return axios.post('/manage/order/delete_service.do', qs.stringify({id})).then(res => Promise.resolve(res.data))
}

export function getWorkingOrder(pageSize = 1000) {
    return axios.post('/manage/working_order/service_list_working_order.do', qs.stringify({pageSize})).then(res => Promise.resolve(res.data))
}

export function getWorkNo() {
    return axios.get('/manage/working_order/get_working_no.do').then(res => Promise.resolve(res.data))
}

export function getWorkDetail(workingId) {
    return axios.post('/manage/working_order/working_order_detail.do', qs.stringify({workingId})).then(res => Promise.resolve(res.data))
}

export function getRealParts(workOrderNo) {
    return axios.post('/manage/close_order/show_really_parts_num.do', qs.stringify({workOrderNo})).then(res => Promise.resolve(res.data))
}

export function getPart(workOrderNo) {
    return axios.post('/manage/working_order/select_spare_parts.do', qs.stringify({workOrderNo})).then(res => Promise.resolve(res.data))
}

export function saveWorkingOrder({workingNo, startDate, workingPlace, project, suratJalanNo, arrangedBy, woStatus, orderId, jobReceiver, sparePartsList}) {
    const data = qs.stringify({
        workingNo,
        startDate,
        workingPlace,
        project,
        suratJalanNo,
        arrangedBy,
        woStatus,
        orderId,
        jobReceiver,
        sparePartsList
    });
    return axios.post('/manage/working_order/save_working_order.do', data).then(res => Promise.resolve(res.data))
}

export function createStockNo(stockOutDate) {
    return axios.post('/stock_change_record/create_stock_out_num.do', qs.stringify({stockOutDate})).then(res => Promise.resolve(res.data))
}

export function getStockOutList(warehouse) {
    return axios.post('/stock_change_record/stock_out_list.do',qs.stringify({warehouse})).then(res => Promise.resolve(res.data))
}

export function getStockWorkNo() {
    return axios.get('/manage/working_order/select_work_no.do').then(res => Promise.resolve(res.data))
}

export function getStockOutDetail(stockOutId) {
    return axios.post('/stock_change_record/stock_out_detail.do', qs.stringify({stockOutId})).then(res => Promise.resolve(res.data))
}



export function stockOut({stockOutNum, stockOutDateStr, applyType, workOrderNo, salesOrderNum, stockOutDetails, customer, receiver,id,warehouse}) {
    const data = qs.stringify({
        stockOutNum,
        stockOutDateStr,
        id,
        applyType,
        workOrderNo,
        salesOrderNum,
        stockOutDetails,
        customer,
        warehouse,
        receiver
    });
    return axios.post('/stock_change_record/stock_out.do', data).then(res => Promise.resolve(res.data))
}
export function saveStockOut({stockOutNum, stockOutDateStr, applyType, workOrderNo, salesOrderNum, stockOutDetails, customer, receiver,id,warehouse}) {
    const data = qs.stringify({
        stockOutNum,
        id,
        stockOutDateStr,
        applyType,
        workOrderNo,
        salesOrderNum,
        stockOutDetails,
        customer,
        warehouse,
        receiver
    });
    return axios.post('/stock_change_record/save_stock_out_record.do', data).then(res => Promise.resolve(res.data))
}

export function getCloseUnit() {
    return axios.get('/service_charge/manage/select_unit.do').then(res=>Promise.resolve(res.data))
}
export function getCloseCategory() {
    return axios.get('/service_charge/manage/select_category.do').then(res=>Promise.resolve(res.data))
}
export function getCloseWorkCode({unit,category,pointCode}) {
    return axios.post('/service_charge/manage/select_service_charge_item.do',qs.stringify({unit,category,pointCode})).then(res=>Promise.resolve(res.data))
}

export function getCloseList() {
    return axios.post('/manage/close_order/show_order_list_by_status.do',qs.stringify({pageSize:1000})).then(res => Promise.resolve(res.data))
}

export function closeOrder({orderId, remarks, recommendation, problem, suggestion, depletes, endDate,handOver,unit,category,causeOfProblem,pointCode}) {
    const data = qs.stringify({orderId, remarks, recommendation, problem, suggestion, depletes, endDate,handOver,unit,category,causeOfProblem,pointCode});
    return axios.post('/manage/close_order/close_order.do', data).then(res => Promise.resolve(res.data))
}

export function getStockInList(warehouse) {
    return axios.post('/stock_change_record/stock_in_list.do',qs.stringify({warehouse})).then(res => Promise.resolve(res.data))
}

export function stockIn({stockInNum, stockInDateStr, stockInDetails,id,exploit,exporter,exportNum,shipNumber,totalBoxes,warehouse,shipA,shipB}) {
    const data = qs.stringify({stockInNum, stockInDateStr, stockInDetails,id,exploit,exporter,exportNum,shipNumber,totalBoxes,warehouse,shipA,shipB});
    return axios.post('/stock_change_record/stock_in.do', data).then(res => Promise.resolve(res.data))
}
export function saveStockIn({stockInNum, stockInDateStr, stockInDetails,id,exploit,exporter,exportNum,shipNumber,totalBoxes,warehouse,shipA,shipB}) {
    const data = qs.stringify({stockInNum, stockInDateStr, stockInDetails,id,exploit,exporter,exportNum,shipNumber,totalBoxes,warehouse,shipA,shipB});
    return axios.post('/stock_change_record/save_stock_in.do', data).then(res => Promise.resolve(res.data))
}
export function getStockInDetail(stockInId) {
    return axios.post('/stock_change_record/stock_in_detail.do', qs.stringify({stockInId})).then(res => Promise.resolve(res.data))
}

export function getReport({startTime, endTime,customer}) {
    return axios.post('/statistical_report/select_statistical_report.do', qs.stringify({
        startTime,
        endTime,
        customer
    })).then(res => Promise.resolve(res.data))
}

export function getProject() {
    return axios.get('/project/show_project.do').then(res => Promise.resolve(res.data))
}

export function getEquipment() {
    return axios.get('/service/equipment_list.do').then(res => Promise.resolve(res.data))
}

export function modEquipment({serviceNum, deliveryDate, contract, equipmentType, brand, sn, engine, model, belongCompany, plateNum, projectId, id}) {
    const data = qs.stringify({
        serviceNum,
        deliveryDate,
        contract,
        equipmentType,
        brand,
        sn,
        engine,
        model,
        belongCompany,
        plateNum,
        projectId,
        id
    });
    return axios.post('/service/modify_equipment.do', data).then(res => Promise.resolve(res.data))
}

export function addEquipment({serviceNum, deliveryDate, contract, equipmentType, brand, sn, engine, model, belongCompany, plateNum, projectId}) {
    const data = qs.stringify({
        serviceNum,
        deliveryDate,
        contract,
        equipmentType,
        brand,
        sn,
        engine,
        model,
        belongCompany,
        plateNum,
        projectId
    });
    return axios.post('/service/add_equipment.do', data).then(res => Promise.resolve(res.data))

}

export function deleteEquipment(id) {
    const data = qs.stringify({id});
    return axios.post('/service/delete_equipment.do', data).then(res => Promise.resolve(res.data))
}

export function deleteProject(id) {
    const data = qs.stringify({id});
    return axios.post('/project/delete_project.do', data).then(res => Promise.resolve(res.data))
}

export function addProject({plateNum, longitude, latitude, projectName, startTimeStr, endTimeStr}) {
    const data = qs.stringify({plateNum, longitude, latitude, projectName, startTimeStr, endTimeStr});
    return axios.post('/project/add_project.do', data).then(res => Promise.resolve(res.data))
}

export function modProject({plateNum, longitude, latitude, projectName, startTimeStr, endTimeStr, id}) {
    const data = qs.stringify({plateNum, longitude, latitude, projectName, startTimeStr, endTimeStr, id});
    return axios.post('/project/modify_project.do', data).then(res => Promise.resolve(res.data))
}

export function getOrder(workingNo) {
    return axios.post('/manage/working_order/report_detail.do', qs.stringify({workingNo})).then(res => Promise.resolve(res.data))
}

export function getAllReport() {
    return axios.post('/history_order/select_by_num_time.do').then(res => Promise.resolve(res.data))
}

export function getTopTen(startTime,endTime) {
    return axios.post('/history_order/select_top_plate_num.do',qs.stringify({startTime,endTime})).then(res=>Promise.resolve(res.data))
}
export function getPointList() {
    return axios.get('/service_charge/manage/show_service_charge_list.do').then(res=>Promise.resolve(res.data))
}

export function getStockInRecord(stockInId) {
    return axios.post('/stock_change_record/show_stock_in_detail.do',qs.stringify({stockInId})).then(res=>Promise.resolve(res.data))
}
export function getStockOutRecord(stockOutId) {
    return axios.post('/stock_change_record/show_stock_out_detail.do',qs.stringify({stockOutId})).then(res=>Promise.resolve(res.data))
}

export function getCostList() {
    return axios.get('/spare_cost/manage/get_all_list.do').then(res => Promise.resolve(res.data))
}
export function addCost(cost) {
    return axios.post('/spare_cost/manage/add_spare_cost.do',qs.stringify(cost)).then(res => Promise.resolve(res.data))
}